package inorder_to_postorder.lexer;

public class Token {
    public final int tag;

    public Token(int c) {
        tag = c;
    }

    public Token(char c) {
        int t = 0;
        switch (c) {
            case '+':
                t = Tag.AND;
                break;
            case '-':
                t = Tag.MINUS;
                break;
            case '*':
                t = Tag.MUL;
                break;
            case '/':
                t = Tag.DIV;
                break;
            case '(':
                t = Tag.LP;
                break;
            case ')':
                t = Tag.RP;
                break;
            default:
                t = c;
                break;
        }
        tag = t;
    }

    public String toString() {
        return "" + (char) tag;
    }


    public int priority() {
        switch (tag) {
            case Tag.LP:
                return 3;
            case Tag.MUL:
            case Tag.DIV:
                return 2;
            case Tag.AND:
            case Tag.MINUS:
                return 1;
            case Tag.EQ:
                return 0;
            default:
                return -1;
        }
    }

    public String transfer() {
        switch (tag) {
            case Tag.AND:
                return "OP_ADD";
            case Tag.MINUS:
                return "OP_SUB";
            case Tag.MUL:
                return "OP_MUL";
            case Tag.DIV:
                return "OP_DIV";
            case Tag.EQ:
                return "OP_EQUAL";
            default:
                return "";
        }
    }
}
